<!DOCTYPE html>
<html>
<body>
<table border=1px>
<tr><textarea id="name"></textarea><br></tr>
<tr>
	<td><button onclick="opFunction(1)">x^2</td> <td><button onclick="opFunction(2)">e^x</td> 
	<td><button onclick="opFunction(3)">tan</td> <td><button onclick="opFunction(4)">cos</td> 
	<td><button onclick="opFunction(5)">sin&nbsp</td> 
</tr>
<tr>
	<td><button onclick="myFunction(9)">&nbsp9&nbsp&nbsp&nbsp</td> <td><button onclick="myFunction(8)">&nbsp8&nbsp&nbsp&nbsp </td> 
	<td><button onclick="myFunction(7)">&nbsp7&nbsp&nbsp&nbsp</td> <td><button onclick="opFunction(6)">&nbsp-&nbsp&nbsp&nbsp</td> 
	<td><button onclick="opFunction(7)">&nbsp*&nbsp&nbsp&nbsp</td> 
</tr>
<tr>
	<td><button onclick="myFunction(6)">&nbsp6&nbsp&nbsp&nbsp</td> <td><button onclick="myFunction(5)">&nbsp5&nbsp&nbsp&nbsp</td> 
	<td><button onclick="myFunction(4)">&nbsp4&nbsp&nbsp&nbsp</td> <td><button onclick="opFunction(8)">&nbsp+&nbsp&nbsp&nbsp</td> 
	<td><button onclick="opFunction(9)">&nbsp/&nbsp&nbsp&nbsp</td> 
</tr>
<tr>
	<td><button onclick="myFunction(3)">&nbsp3&nbsp&nbsp&nbsp</td> <td><button onclick="myFunction(2)">&nbsp2&nbsp&nbsp&nbsp</td> 
	<td><button onclick="myFunction(1)">&nbsp1&nbsp&nbsp&nbsp</td> <td><button onclick="myFunction(0)">&nbsp0&nbsp&nbsp&nbsp</td> 
	<td><button onclick="equalFunction()">&nbsp=&nbsp&nbsp&nbsp</td> 
</tr>
</table>
<script>
var sel=0;
var val1=0;
var val2=0;
var op=0;
var res=0;
function myFunction(p1) {

	if(sel==0){val1=(val1*10)+p1;
	document.getElementById("name").innerHTML=val1;}
	else {val2=(val2*10)+p1;
	document.getElementById("name").innerHTML=val2;}
}
function opFunction(p1)
{
	if(p1==1)
	{
		document.getElementById("name").innerHTML=(val1*val1);
		val1=0;		
	}
	else if(p1==2)
	{
		document.getElementById("name").innerHTML=Math.exp(val1);
		val1=0;	
	}
	else if(p1==3)
	{
		document.getElementById("name").innerHTML=Math.tan(val1);
		val1=0;	
	}
	else if(p1==4)
	{
		document.getElementById("name").innerHTML=Math.cos(val1);
		val1=0;	
	}
	else if(p1==5)
	{
		document.getElementById("name").innerHTML=Math.sin(val1);
		val1=0;	
	}	
	else if(sel==0){
		op=p1;
		sel=1;
		document.getElementById("name").innerHTML="";
	}
	else{
	
	document.getElementById("name").innerHTML="Syntax Error";
	val1=0;
	val2=0;
	}
	
}
function equalFunction()
{
	if(sel==0) 
	document.getElementById("name").innerHTML=val1;
	else
	{
		switch(op)
		{
			case 6:res=val1-val2;
			break;
			case 7:res=val1*val2;
			break;
			case 8:res=val1+val2;
			break;
			case 9:res=val1/val2;
			break;
			default:document.getElementById("name").innerHTML="Syntax Error";
			val1=val2=op=sel=0;
			break;
			return;
		}
		document.getElementById("name").innerHTML=res;
		val1=val2=op=sel=0;
	}
}
</script>

</body>
</html>
